import {
	http
} from '@/utils/http'

/**
 * 登录
 */
export function loginApi(data) {
	return http({
		method: 'POST',
		url: '/system/login/doLogin',
		data
	})
}

/**
 * produceLoginApi 登录(产品线记录登录信息)
 */
export function produceLoginApi(data) {
	return new Promise(async (resolve, reject) => {
		try{
			const res = await http({
			  method: 'POST',
			  url: '/mes/mesmemberloginrecord/login',
			  data
			});
			resolve(res);
		}catch(e){
			//TODO handle the exception
			reject(e)
		}
	
	  });
}


/**
 * 注销API
 */
export function logoutApi() {
	return http({
		method: 'POST',
		url: '/system/login/logout',
	})
}

/**
 * 修改密码
 */
export function modifyPasswordApi(data) {
	return http({
		method: 'POST',
		url: '/system/login/modifyPassword',
		data
	})
}

// 下载
export function downLoadApi(data) {
	return http({
		method: "POST",
		url: "/system/sysRole/export",
		data: data,
	});
}

/**
 * 登录成功后获取用户信息（昵称、头像、权限集合和角色集合）
 */
export function getUserInfo() {
	return http({
		url: "/system/login/getLoginInfo",
		method: "POST",
	});
}
/**
 * 登录成功后获取按钮权限集合
 */
export function getButtonInfo() {
	return http({
		url: "/system/loginUserPower/codes",
		method: "POST",
	});
}

/**
 * 获取未读消息条数
 */
export function getUnReadMessageApi() {
	return http({
		url: "/system/sysmessage/userUnreadMessCount",
		method: "POST",
		data: {},
	});
}

/**
 * 获取路由列表
 */
const APPTYPE = process.env.VITE_APP_TYPE;
export function getRoutesApi(type: string) {
  return http({
    url: `/system/loginUserPower/tree?applicationType=${APPTYPE}&parentMenuId=${type}`,
    method: "POST",
  });
}
/**
 * 获取所有字典集合
 */
export function getDictInfo() {
  return http({
    url: "/system/dictionary/getAllDictionaryItems",
    method: "POST",
    data: {},
  });
}
/**
 * 获取当前登陆人信息
 */
export function getPersonLoginInfo() {
  return http({
    url: "/system/personLogin/getPersonLoginInfo",
    method: "POST",
    data: {},
  });
}